#include<cstdio>//BAONI
#include<algorithm>
using namespace std;
template<class T>void read(T &x)
{
	x=0;int f=0;char ch=getchar();
	while(ch<'0'||ch>'9') { f|=(ch=='-'); ch=getchar(); }
	while(ch<='9'&&ch>='0') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
	x = f ? -x : x;
	return ;
}

const int Mod=99999997;

int n;
struct node{
	int val,sit;
	friend bool operator<(const node a,const node b)
	{
		return a.val<b.val;
	}
}A[1000010],B[1000010];

int list[1000010];

int Tree[1000010];

int lowbit(int x)
{
	return x&(-x);
}

int sum(int x)
{
	int S=0;
	while(x>0)
	{
		S+=Tree[x];
		x-=lowbit(x);
	}
	return S;
}

void Add(int x)
{
	while(x<=n)
	{
		Tree[x]++;
		x+=lowbit(x);
	}
	return ;
}

int main()
{
	read(n);

	for(int i=1;i<=n;++i)
		read(A[i].val),A[i].sit=i;
	for(int i=1;i<=n;++i)
		read(B[i].val),B[i].sit=i;

	sort(A+1,A+1+n);
	sort(B+1,B+1+n);
	for(int i=1;i<=n;++i)
		list[A[i].sit]=B[i].sit;

	int ans=0;
	for(int i=1;i<=n;++i)
	{
		Add(list[i]);
		ans+=(i-sum(list[i]));
		ans%=Mod;
	}
	printf("%d",ans);
	return 0;
}